import { saveSmsReceiverType } from '@/api/sms'
import { ref } from 'vue'

export default () => {
  // 接收者类型表单
  const receiverTypeForm = ref<{ empIds: Array<string>; roleTypes: Array<string> }>({
    empIds: [],
    roleTypes: [],
  })

  /**
   * 保存加载
   */
  const saveReceiverTypeLoading = ref(false)

  /**
   * 保存短信接收者类型
   * @param {String} smsTemplateId - 短信模板id
   */
  const saveReceiverType = async (smsTemplateId: string) => {
    saveReceiverTypeLoading.value = true
    const res = await saveSmsReceiverType(smsTemplateId, receiverTypeForm.value)
    saveReceiverTypeLoading.value = false
    return res.data
  }

  return {
    receiverTypeForm,
    saveReceiverTypeLoading,
    saveReceiverType,
  }
}
